From afd7dba2eab3fa30b6abf625bdb7e5599ab62b3a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:48:34 +0000 Subject: [PATCH 01/59] 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 6cbf2db..373828d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove onc var castReturn = require( '@stdlib/complex-base-cast-return' ); var complexCtors = require( '@stdlib/complex-ctors' ); var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 9332479..205ad73 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-identity-function": "^0.1.0" }, From d0370f025146652fad5b5554950c0aefb13f6d58 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:50:31 +0000 Subject: [PATCH 02/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 139 - package.json | 84 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1470 ----- test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 8627 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index afed1df..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var n=q(function(R,v){ -var l=require('@stdlib/ndarray-base-assert-is-safe-data-type-cast/dist'),y=require('@stdlib/ndarray-base-assert-is-same-kind-data-type-cast/dist'),c=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),d=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),f=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),m=require('@stdlib/ndarray-base-broadcast-array/dist'),C=require('@stdlib/ndarray-base-unary/dist'),u=require('@stdlib/utils-identity-function/dist'),D=require('@stdlib/complex-base-cast-return/dist'),T=require('@stdlib/complex-ctors/dist'),g=require('@stdlib/ndarray-base-slice/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist');function w(a,r,o,p){var s,i,t,e;if(t=a.dtype,e=r.dtype,l(t,e))f(t)&&d(e)?i=D(u,1,T(e)):i=u;else if(c(e)&&y(t,e))i=u;else throw new TypeError(h("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",t,e));return s=g(r,o,p,!0),a=m(a,s.shape),C([a,s],i),r}v.exports=w -});var b=n();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d107867..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 isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );\nvar isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nvar identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a mutable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAa,QAAS,oDAAqD,EAC3EC,EAAiB,QAAS,yDAA0D,EACpFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAAoB,QAAS,iEAAkE,EAC/FC,EAAiB,QAAS,+CAAgD,EAC1EC,EAAY,QAAS,sCAAuC,EAC5DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,iCAAkC,EACtDC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAE,MACRO,EAAMN,EAAE,MAGHd,EAAYmB,EAAKC,CAAI,EAEpBhB,EAAgBe,CAAI,GAAKhB,EAAmBiB,CAAI,EAEpDF,EAAMV,EAAYD,EAAU,EAAGE,EAAcW,CAAI,CAAE,EAGnDF,EAAMX,UAIEL,EAAyBkB,CAAI,GAAKnB,EAAgBkB,EAAKC,CAAI,EAEpEF,EAAMX,MAEN,OAAM,IAAI,UAAWI,EAAQ,kHAAmHQ,EAAKC,CAAI,CAAE,EAG5J,OAAAH,EAAOP,EAAOI,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIR,EAAWQ,EAAGI,EAAK,KAAM,EAG7BX,EAAO,CAAEO,EAAGI,CAAK,EAAGC,CAAI,EAGjBJ,CACR,CAKAf,EAAO,QAAUa,ICjEjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isSafeCast", "isSameKindCast", "isFloatingPointDataType", "isComplexDataType", "isRealDataType", "broadcast", "unary", "identity", "castReturn", "complexCtors", "slice", "format", "sliceAssign", "x", "y", "s", "strict", "view", "fcn", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d7f9c68..2571b69 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc222d3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,c,v){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,c,v,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9990b8d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a mutable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;4uCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 373828d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' ); -var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' ); -var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support -var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign` -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var fcn; - var xdt; - var ydt; - - xdt = x.dtype; - ydt = y.dtype; - - // Safe casts are always allowed... - if ( isSafeCast( xdt, ydt ) ) { - // Check for real-to-complex conversion... - if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) { - // Need to cast a real number to a complex number: - fcn = castReturn( identity, 1, complexCtors( ydt ) ); - } else { - // Should only be real->real and complex->complex: - fcn = identity; - } - } - // Allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) { - // At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions: - fcn = identity; - } else { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a mutable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, view.shape ); - - // Set elements from `x` in `y`: - unary( [ x, view ], fcn ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 205ad73..dae1969 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/complex-base-cast-return": "^0.1.0", - "@stdlib/complex-ctors": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-real-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-identity-function": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4bc0343 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c8fc443..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 79094d6b7d57b1db25898b8de14b2a91e29ceb4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:02:06 +0000 Subject: [PATCH 03/59] 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 6cbf2db..373828d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove onc var castReturn = require( '@stdlib/complex-base-cast-return' ); var complexCtors = require( '@stdlib/complex-ctors' ); var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 9332479..205ad73 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-identity-function": "^0.1.0" }, From 41adf8439d23c41ee7c2c9434cdfb7fc5c58a6ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:38:50 +0000 Subject: [PATCH 04/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 2571b69..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc222d3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,c,v){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,c,v,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9990b8d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a mutable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;4uCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4bc0343..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From faca65c083eef94a9fbe727ddb2c024a6643bb25 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:40:31 +0000 Subject: [PATCH 05/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 139 - package.json | 84 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1470 ----- test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 8627 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index afed1df..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var n=q(function(R,v){ -var l=require('@stdlib/ndarray-base-assert-is-safe-data-type-cast/dist'),y=require('@stdlib/ndarray-base-assert-is-same-kind-data-type-cast/dist'),c=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),d=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),f=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),m=require('@stdlib/ndarray-base-broadcast-array/dist'),C=require('@stdlib/ndarray-base-unary/dist'),u=require('@stdlib/utils-identity-function/dist'),D=require('@stdlib/complex-base-cast-return/dist'),T=require('@stdlib/complex-ctors/dist'),g=require('@stdlib/ndarray-base-slice/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist');function w(a,r,o,p){var s,i,t,e;if(t=a.dtype,e=r.dtype,l(t,e))f(t)&&d(e)?i=D(u,1,T(e)):i=u;else if(c(e)&&y(t,e))i=u;else throw new TypeError(h("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",t,e));return s=g(r,o,p,!0),a=m(a,s.shape),C([a,s],i),r}v.exports=w -});var b=n();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d107867..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 isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );\nvar isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nvar identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a mutable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAa,QAAS,oDAAqD,EAC3EC,EAAiB,QAAS,yDAA0D,EACpFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAAoB,QAAS,iEAAkE,EAC/FC,EAAiB,QAAS,+CAAgD,EAC1EC,EAAY,QAAS,sCAAuC,EAC5DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,iCAAkC,EACtDC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAE,MACRO,EAAMN,EAAE,MAGHd,EAAYmB,EAAKC,CAAI,EAEpBhB,EAAgBe,CAAI,GAAKhB,EAAmBiB,CAAI,EAEpDF,EAAMV,EAAYD,EAAU,EAAGE,EAAcW,CAAI,CAAE,EAGnDF,EAAMX,UAIEL,EAAyBkB,CAAI,GAAKnB,EAAgBkB,EAAKC,CAAI,EAEpEF,EAAMX,MAEN,OAAM,IAAI,UAAWI,EAAQ,kHAAmHQ,EAAKC,CAAI,CAAE,EAG5J,OAAAH,EAAOP,EAAOI,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIR,EAAWQ,EAAGI,EAAK,KAAM,EAG7BX,EAAO,CAAEO,EAAGI,CAAK,EAAGC,CAAI,EAGjBJ,CACR,CAKAf,EAAO,QAAUa,ICjEjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isSafeCast", "isSameKindCast", "isFloatingPointDataType", "isComplexDataType", "isRealDataType", "broadcast", "unary", "identity", "castReturn", "complexCtors", "slice", "format", "sliceAssign", "x", "y", "s", "strict", "view", "fcn", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4c12645..9b7886c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..85a0e73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fdd9916 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a mutable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 373828d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' ); -var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' ); -var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support -var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign` -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var fcn; - var xdt; - var ydt; - - xdt = x.dtype; - ydt = y.dtype; - - // Safe casts are always allowed... - if ( isSafeCast( xdt, ydt ) ) { - // Check for real-to-complex conversion... - if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) { - // Need to cast a real number to a complex number: - fcn = castReturn( identity, 1, complexCtors( ydt ) ); - } else { - // Should only be real->real and complex->complex: - fcn = identity; - } - } - // Allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) { - // At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions: - fcn = identity; - } else { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a mutable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, view.shape ); - - // Set elements from `x` in `y`: - unary( [ x, view ], fcn ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 205ad73..dae1969 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/complex-base-cast-return": "^0.1.0", - "@stdlib/complex-ctors": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-real-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-identity-function": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9ef3683 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c8fc443..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 4176860a1ea40164fd0c3c1f467dd796337675ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:48:14 +0000 Subject: [PATCH 06/59] 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 5b96a56..c39bded 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove onc var castReturn = require( '@stdlib/complex-base-cast-return' ); var complexCtors = require( '@stdlib/complex-ctors' ); var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 9332479..205ad73 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-identity-function": "^0.1.0" }, From 9a31cf1b1de048739e7312728b7373a5e540e41b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:53:14 +0000 Subject: [PATCH 07/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 9b7886c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 85a0e73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fdd9916..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a mutable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9ef3683..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 57e8da603f928de65453a2ef4858640896119a42 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:54:58 +0000 Subject: [PATCH 08/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 139 - package.json | 84 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1470 ----- test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 8627 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index afed1df..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var n=q(function(R,v){ -var l=require('@stdlib/ndarray-base-assert-is-safe-data-type-cast/dist'),y=require('@stdlib/ndarray-base-assert-is-same-kind-data-type-cast/dist'),c=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),d=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),f=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),m=require('@stdlib/ndarray-base-broadcast-array/dist'),C=require('@stdlib/ndarray-base-unary/dist'),u=require('@stdlib/utils-identity-function/dist'),D=require('@stdlib/complex-base-cast-return/dist'),T=require('@stdlib/complex-ctors/dist'),g=require('@stdlib/ndarray-base-slice/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist');function w(a,r,o,p){var s,i,t,e;if(t=a.dtype,e=r.dtype,l(t,e))f(t)&&d(e)?i=D(u,1,T(e)):i=u;else if(c(e)&&y(t,e))i=u;else throw new TypeError(h("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",t,e));return s=g(r,o,p,!0),a=m(a,s.shape),C([a,s],i),r}v.exports=w -});var b=n();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 526a01c..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 isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );\nvar isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nvar identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAa,QAAS,oDAAqD,EAC3EC,EAAiB,QAAS,yDAA0D,EACpFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAAoB,QAAS,iEAAkE,EAC/FC,EAAiB,QAAS,+CAAgD,EAC1EC,EAAY,QAAS,sCAAuC,EAC5DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,iCAAkC,EACtDC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAE,MACRO,EAAMN,EAAE,MAGHd,EAAYmB,EAAKC,CAAI,EAEpBhB,EAAgBe,CAAI,GAAKhB,EAAmBiB,CAAI,EAEpDF,EAAMV,EAAYD,EAAU,EAAGE,EAAcW,CAAI,CAAE,EAGnDF,EAAMX,UAIEL,EAAyBkB,CAAI,GAAKnB,EAAgBkB,EAAKC,CAAI,EAEpEF,EAAMX,MAEN,OAAM,IAAI,UAAWI,EAAQ,kHAAmHQ,EAAKC,CAAI,CAAE,EAG5J,OAAAH,EAAOP,EAAOI,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIR,EAAWQ,EAAGI,EAAK,KAAM,EAG7BX,EAAO,CAAEO,EAAGI,CAAK,EAAGC,CAAI,EAGjBJ,CACR,CAKAf,EAAO,QAAUa,ICjEjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isSafeCast", "isSameKindCast", "isFloatingPointDataType", "isComplexDataType", "isRealDataType", "broadcast", "unary", "identity", "castReturn", "complexCtors", "slice", "format", "sliceAssign", "x", "y", "s", "strict", "view", "fcn", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4c12645..9b7886c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..85a0e73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..483b737 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 c39bded..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' ); -var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' ); -var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support -var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign` -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var fcn; - var xdt; - var ydt; - - xdt = x.dtype; - ydt = y.dtype; - - // Safe casts are always allowed... - if ( isSafeCast( xdt, ydt ) ) { - // Check for real-to-complex conversion... - if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) { - // Need to cast a real number to a complex number: - fcn = castReturn( identity, 1, complexCtors( ydt ) ); - } else { - // Should only be real->real and complex->complex: - fcn = identity; - } - } - // Allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) { - // At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions: - fcn = identity; - } else { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, view.shape ); - - // Set elements from `x` in `y`: - unary( [ x, view ], fcn ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 205ad73..dae1969 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/complex-base-cast-return": "^0.1.0", - "@stdlib/complex-ctors": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-real-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-identity-function": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..41149ff --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c8fc443..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 4eb940b46dfe9b6f8760d266143db17430caf2c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 17:14:12 +0000 Subject: [PATCH 09/59] 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 5b96a56..c39bded 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove onc var castReturn = require( '@stdlib/complex-base-cast-return' ); var complexCtors = require( '@stdlib/complex-ctors' ); var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 9332479..205ad73 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-identity-function": "^0.1.0" }, From e6f85e87e460bf22a18e1df8db9939c13c0dc655 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 02:50:41 +0000 Subject: [PATCH 10/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 9b7886c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 85a0e73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 483b737..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 41149ff..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 527b717636f4824937d3ec359debecc59d4e9a1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 02:52:10 +0000 Subject: [PATCH 11/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 139 - package.json | 84 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1470 ----- test/test.js | 1470 ----- 42 files changed, 6213 insertions(+), 8628 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 71b9a78..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:35:58.455Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index afed1df..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var n=q(function(R,v){ -var l=require('@stdlib/ndarray-base-assert-is-safe-data-type-cast/dist'),y=require('@stdlib/ndarray-base-assert-is-same-kind-data-type-cast/dist'),c=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),d=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),f=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),m=require('@stdlib/ndarray-base-broadcast-array/dist'),C=require('@stdlib/ndarray-base-unary/dist'),u=require('@stdlib/utils-identity-function/dist'),D=require('@stdlib/complex-base-cast-return/dist'),T=require('@stdlib/complex-ctors/dist'),g=require('@stdlib/ndarray-base-slice/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist');function w(a,r,o,p){var s,i,t,e;if(t=a.dtype,e=r.dtype,l(t,e))f(t)&&d(e)?i=D(u,1,T(e)):i=u;else if(c(e)&&y(t,e))i=u;else throw new TypeError(h("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",t,e));return s=g(r,o,p,!0),a=m(a,s.shape),C([a,s],i),r}v.exports=w -});var b=n();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 526a01c..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 isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );\nvar isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nvar identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAa,QAAS,oDAAqD,EAC3EC,EAAiB,QAAS,yDAA0D,EACpFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAAoB,QAAS,iEAAkE,EAC/FC,EAAiB,QAAS,+CAAgD,EAC1EC,EAAY,QAAS,sCAAuC,EAC5DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,iCAAkC,EACtDC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAE,MACRO,EAAMN,EAAE,MAGHd,EAAYmB,EAAKC,CAAI,EAEpBhB,EAAgBe,CAAI,GAAKhB,EAAmBiB,CAAI,EAEpDF,EAAMV,EAAYD,EAAU,EAAGE,EAAcW,CAAI,CAAE,EAGnDF,EAAMX,UAIEL,EAAyBkB,CAAI,GAAKnB,EAAgBkB,EAAKC,CAAI,EAEpEF,EAAMX,MAEN,OAAM,IAAI,UAAWI,EAAQ,kHAAmHQ,EAAKC,CAAI,CAAE,EAG5J,OAAAH,EAAOP,EAAOI,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIR,EAAWQ,EAAGI,EAAK,KAAM,EAG7BX,EAAO,CAAEO,EAAGI,CAAK,EAAGC,CAAI,EAGjBJ,CACR,CAKAf,EAAO,QAAUa,ICjEjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isSafeCast", "isSameKindCast", "isFloatingPointDataType", "isComplexDataType", "isRealDataType", "broadcast", "unary", "identity", "castReturn", "complexCtors", "slice", "format", "sliceAssign", "x", "y", "s", "strict", "view", "fcn", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4c12645..9b7886c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..85a0e73 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..483b737 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 c39bded..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' ); -var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' ); -var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support -var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign` -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var fcn; - var xdt; - var ydt; - - xdt = x.dtype; - ydt = y.dtype; - - // Safe casts are always allowed... - if ( isSafeCast( xdt, ydt ) ) { - // Check for real-to-complex conversion... - if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) { - // Need to cast a real number to a complex number: - fcn = castReturn( identity, 1, complexCtors( ydt ) ); - } else { - // Should only be real->real and complex->complex: - fcn = identity; - } - } - // Allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) { - // At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions: - fcn = identity; - } else { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, view.shape ); - - // Set elements from `x` in `y`: - unary( [ x, view ], fcn ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 205ad73..dae1969 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/complex-base-cast-return": "^0.1.0", - "@stdlib/complex-ctors": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-real-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-identity-function": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..02a74ca --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c8fc443..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 5bf3ebd7aea05096d7b3f3d0e2a9100905ecb662 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 20:23:27 +0000 Subject: [PATCH 12/59] 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 5b96a56..c39bded 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove onc var castReturn = require( '@stdlib/complex-base-cast-return' ); var complexCtors = require( '@stdlib/complex-ctors' ); var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index f7f79b2..bbad050 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-identity-function": "^0.1.1" }, From fb79e0d8bb52b61fae68a4151b43749e5bb2283f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:58:10 +0000 Subject: [PATCH 13/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 9b7886c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 85a0e73..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 483b737..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 02a74ca..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a5b56da1ea7ebce01c8481de49061434aefa86ec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:59:16 +0000 Subject: [PATCH 14/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 139 - package.json | 84 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1470 ----- test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 8627 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 8e75ab9..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var q=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var n=q(function(R,v){ -var l=require('@stdlib/ndarray-base-assert-is-safe-data-type-cast/dist'),y=require('@stdlib/ndarray-base-assert-is-same-kind-data-type-cast/dist'),c=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),d=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),f=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),m=require('@stdlib/ndarray-base-broadcast-array/dist'),C=require('@stdlib/ndarray-base-unary/dist'),u=require('@stdlib/utils-identity-function/dist'),D=require('@stdlib/complex-base-cast-return/dist'),T=require('@stdlib/complex-ctors/dist'),g=require('@stdlib/ndarray-base-slice/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist');function w(a,r,o,p){var s,i,t,e;if(t=a.dtype,e=r.dtype,l(t,e))f(t)&&d(e)?i=D(u,1,T(e)):i=u;else if(c(e)&&y(t,e))i=u;else throw new TypeError(h('1jPF0',t,e));return s=g(r,o,p,!0),a=m(a,s.shape),C([a,s],i),r}v.exports=w -});var b=n();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 526a01c..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 isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );\nvar isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nvar identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAa,QAAS,oDAAqD,EAC3EC,EAAiB,QAAS,yDAA0D,EACpFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAAoB,QAAS,iEAAkE,EAC/FC,EAAiB,QAAS,+CAAgD,EAC1EC,EAAY,QAAS,sCAAuC,EAC5DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,iCAAkC,EACtDC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAE,MACRO,EAAMN,EAAE,MAGHd,EAAYmB,EAAKC,CAAI,EAEpBhB,EAAgBe,CAAI,GAAKhB,EAAmBiB,CAAI,EAEpDF,EAAMV,EAAYD,EAAU,EAAGE,EAAcW,CAAI,CAAE,EAGnDF,EAAMX,UAIEL,EAAyBkB,CAAI,GAAKnB,EAAgBkB,EAAKC,CAAI,EAEpEF,EAAMX,MAEN,OAAM,IAAI,UAAWI,EAAQ,kHAAmHQ,EAAKC,CAAI,CAAE,EAG5J,OAAAH,EAAOP,EAAOI,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIR,EAAWQ,EAAGI,EAAK,KAAM,EAG7BX,EAAO,CAAEO,EAAGI,CAAK,EAAGC,CAAI,EAGjBJ,CACR,CAKAf,EAAO,QAAUa,ICjEjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isSafeCast", "isSameKindCast", "isFloatingPointDataType", "isComplexDataType", "isRealDataType", "broadcast", "unary", "identity", "castReturn", "complexCtors", "slice", "format", "sliceAssign", "x", "y", "s", "strict", "view", "fcn", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4c12645..9b7886c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2eb28d6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..483b737 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 c39bded..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' ); -var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' ); -var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support -var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign` -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var fcn; - var xdt; - var ydt; - - xdt = x.dtype; - ydt = y.dtype; - - // Safe casts are always allowed... - if ( isSafeCast( xdt, ydt ) ) { - // Check for real-to-complex conversion... - if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) { - // Need to cast a real number to a complex number: - fcn = castReturn( identity, 1, complexCtors( ydt ) ); - } else { - // Should only be real->real and complex->complex: - fcn = identity; - } - } - // Allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) { - // At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions: - fcn = identity; - } else { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, view.shape ); - - // Set elements from `x` in `y`: - unary( [ x, view ], fcn ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index bbad050..dae1969 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/complex-base-cast-return": "^0.1.0", - "@stdlib/complex-ctors": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-real-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-identity-function": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..835c181 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c8fc443..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 4de0f7e4a83d87cfe90daa2f8432bcca448dc133 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:26:51 +0000 Subject: [PATCH 15/59] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a53289c..f3c5e3f 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-identity-function": "^0.1.1" }, From 94d6e011c0218d12169cb7f76ef2c657da39ee63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:29:06 +0000 Subject: [PATCH 16/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 9b7886c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2eb28d6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(j,h,v,c){var y,b,f,g;if(f=j.dtype,g=h.dtype,s(f,g))b=a(f)&&r(g)?m(n,1,o(g)):n;else{if(!e(g)||!t(f,g))throw new TypeError(l("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",f,g));b=n}return y=p(h,v,c,!0),j=d(j,y.shape),i([j,y],b),h}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 483b737..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = x.dtype;\n\tydt = y.dtype;\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, view.shape );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","dtype","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","shape","unary"],"mappings":";;mvCA+FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMN,EAAEQ,MACRD,EAAMN,EAAEO,MAGHC,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGI,EAAKiB,OAGvBC,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 835c181..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fe4b03b13ae8d2a3d2107539b4d6b4a892b51309 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:30:27 +0000 Subject: [PATCH 17/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 141 - package.json | 86 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1470 ----- test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 8631 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f3626e6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var l=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var o=l(function(A,n){ -var c=require('@stdlib/ndarray-base-assert-is-safe-data-type-cast/dist'),y=require('@stdlib/ndarray-base-assert-is-same-kind-data-type-cast/dist'),f=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),d=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),m=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),g=require('@stdlib/ndarray-base-broadcast-array/dist'),D=require('@stdlib/ndarray-base-unary/dist'),u=require('@stdlib/utils-identity-function/dist'),T=require('@stdlib/complex-base-cast-return/dist'),C=require('@stdlib/complex-ctors/dist'),h=require('@stdlib/ndarray-base-slice/dist'),v=require('@stdlib/ndarray-base-dtype/dist'),w=require('@stdlib/ndarray-base-shape/dist'),S=require('@stdlib/error-tools-fmtprodmsg/dist');function b(a,r,q,p){var s,i,t,e;if(t=v(a),e=v(r),c(t,e))m(t)&&d(e)?i=T(u,1,C(e)):i=u;else if(f(e)&&y(t,e))i=u;else throw new TypeError(S('1jPF0',t,e));return s=h(r,q,p,!0),a=g(a,w(s,!0)),D([a,s],i),r}n.exports=b -});var x=o();module.exports=x; -/** @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 344b3f4..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 isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );\nvar isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nvar identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAa,QAAS,oDAAqD,EAC3EC,EAAiB,QAAS,yDAA0D,EACpFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAAoB,QAAS,iEAAkE,EAC/FC,EAAiB,QAAS,+CAAgD,EAC1EC,EAAY,QAAS,sCAAuC,EAC5DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,iCAAkC,EACtDC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAMV,EAAUI,CAAE,EAClBO,EAAMX,EAAUK,CAAE,EAGbhB,EAAYqB,EAAKC,CAAI,EAEpBlB,EAAgBiB,CAAI,GAAKlB,EAAmBmB,CAAI,EAEpDF,EAAMZ,EAAYD,EAAU,EAAGE,EAAca,CAAI,CAAE,EAGnDF,EAAMb,UAIEL,EAAyBoB,CAAI,GAAKrB,EAAgBoB,EAAKC,CAAI,EAEpEF,EAAMb,MAEN,OAAM,IAAI,UAAWM,EAAQ,kHAAmHQ,EAAKC,CAAI,CAAE,EAG5J,OAAAH,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIV,EAAWU,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCb,EAAO,CAAES,EAAGI,CAAK,EAAGC,CAAI,EAGjBJ,CACR,CAKAjB,EAAO,QAAUe,ICnEjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isSafeCast", "isSameKindCast", "isFloatingPointDataType", "isComplexDataType", "isRealDataType", "broadcast", "unary", "identity", "castReturn", "complexCtors", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "fcn", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4c12645..9b7886c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6d3f79d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(v,b,c,y){var f,g,x,u;if(x=j(v),u=j(b),s(x,u))g=a(x)&&r(u)?m(n,1,o(u)):n;else{if(!e(u)||!t(x,u))throw new TypeError(h("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",x,u));g=n}return f=p(b,c,y,!0),v=d(v,l(f,!0)),i([v,f],g),b}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5ac8d75 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","getDType","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","getShape","unary"],"mappings":";;s5CAiGA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUR,GAChBO,EAAMC,EAAUP,GAGXQ,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGqB,EAAUjB,GAAM,IAGlCkB,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 dfbabee..0000000 --- a/lib/main.js +++ /dev/null @@ -1,141 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' ); -var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' ); -var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var unary = require( '@stdlib/ndarray-base-unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support -var identity = require( '@stdlib/utils-identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign` -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var fcn; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed... - if ( isSafeCast( xdt, ydt ) ) { - // Check for real-to-complex conversion... - if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) { - // Need to cast a real number to a complex number: - fcn = castReturn( identity, 1, complexCtors( ydt ) ); - } else { - // Should only be real->real and complex->complex: - fcn = identity; - } - } - // Allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) { - // At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions: - fcn = identity; - } else { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - unary( [ x, view ], fcn ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index f3c5e3f..dae1969 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,65 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/complex-base-cast-return": "^0.1.0", - "@stdlib/complex-ctors": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-real-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "github:stdlib-js/ndarray-base-dtype#main", - "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/ndarray-base-slice": "github:stdlib-js/ndarray-base-slice#main", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-identity-function": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..723c59f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index c8fc443..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 7cefcfc91f897da97bafc05f761ec00ee61ad3e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:26:47 +0000 Subject: [PATCH 18/59] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 081b9ee..e5aa8db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From a8a0172ab95d0d0000fab19ce5dacba076b3fe8a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:28:10 +0000 Subject: [PATCH 19/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 9b7886c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6d3f79d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-floating-point-data-type@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-complex-floating-point-data-type@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-real-data-type@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-identity-function@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(v,b,c,y){var f,g,x,u;if(x=j(v),u=j(b),s(x,u))g=a(x)&&r(u)?m(n,1,o(u)):n;else{if(!e(u)||!t(x,u))throw new TypeError(h("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",x,u));g=n}return f=p(b,c,y,!0),v=d(v,l(f,!0)),i([v,f],g),b}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5ac8d75..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isSafeCast from '@stdlib/ndarray-base-assert-is-safe-data-type-cast';\nimport isSameKindCast from '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast';\nimport isFloatingPointDataType from '@stdlib/ndarray-base-assert-is-floating-point-data-type';\nimport isComplexDataType from '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type';\nimport isRealDataType from '@stdlib/ndarray-base-assert-is-real-data-type';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport unary from '@stdlib/ndarray-base-unary'; // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support\nimport identity from '@stdlib/utils-identity-function'; // TODO: remove once use `@stdlib/ndarray/base/assign`\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar fcn;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed...\n\tif ( isSafeCast( xdt, ydt ) ) {\n\t\t// Check for real-to-complex conversion...\n\t\tif ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {\n\t\t\t// Need to cast a real number to a complex number:\n\t\t\tfcn = castReturn( identity, 1, complexCtors( ydt ) );\n\t\t} else {\n\t\t\t// Should only be real->real and complex->complex:\n\t\t\tfcn = identity;\n\t\t}\n\t}\n\t// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\telse if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {\n\t\t// At this point, we know that the input data type and output data type are of the same \"kind\" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:\n\t\tfcn = identity;\n\t} else {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tunary( [ x, view ], fcn );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","fcn","xdt","ydt","getDType","isSafeCast","isRealDataType","isComplexDataType","castReturn","identity","complexCtors","isFloatingPointDataType","isSameKindCast","TypeError","format","slice","broadcast","getShape","unary"],"mappings":";;s5CAiGA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUR,GAChBO,EAAMC,EAAUP,GAGXQ,EAAYH,EAAKC,GAIpBF,EAFIK,EAAgBJ,IAASK,EAAmBJ,GAE1CK,EAAYC,EAAU,EAAGC,EAAcP,IAGvCM,MAIH,KAAKE,EAAyBR,KAASS,EAAgBV,EAAKC,GAIhE,MAAM,IAAIU,UAAWC,EAAQ,kHAAmHZ,EAAKC,IAFrJF,EAAMQ,CAGN,CAWD,OATAT,EAAOe,EAAOlB,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIoB,EAAWpB,EAAGqB,EAAUjB,GAAM,IAGlCkB,EAAO,CAAEtB,EAAGI,GAAQC,GAGbJ,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 723c59f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ce87b615151ba4e3b15d363b0ddcc6be7159888e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:29:22 +0000 Subject: [PATCH 20/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 7174 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4c12645..9b7886c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df28084 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5315b26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;kqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 2829a7a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index e5aa8db..35f4143 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assign": "github:stdlib-js/ndarray-base-assign#main", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..91c3da5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 1978f2665eda1c9e6596500ad9c9cbf3873f3045 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:30:33 +0000 Subject: [PATCH 21/59] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf70bd0..bc65628 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.1.0-esm/index.mjs'; ``` #### sliceAssign( x, y, slice, strict ) @@ -149,7 +149,7 @@ import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-s import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import ndzeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.1.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 2a2683dae43237e40771c0f4c1c456bfd641b96a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:30:34 +0000 Subject: [PATCH 22/59] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc65628..f2402cd 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-slice-assign/tags). For example, + ```javascript import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.1.0-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-s import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import ndzeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.1.0-esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From e1efbfbf75a9d06d76ac11d5efa2e724a2967b99 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:26:48 +0000 Subject: [PATCH 23/59] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 081b9ee..e5aa8db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 6822d51e4c789179ad8fffb47db86ac5ba1f67e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:30:04 +0000 Subject: [PATCH 24/59] Remove files --- index.d.ts | 810 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6992 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 9b7886c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,810 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df28084..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5315b26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;kqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 91c3da5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 47cece207b29a1727c0312d9e02d701821d8542c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:31:25 +0000 Subject: [PATCH 25/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 7174 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 9ecba89..0fe4150 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df28084 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5315b26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;kqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 2829a7a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index e5aa8db..35f4143 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assign": "github:stdlib-js/ndarray-base-assign#main", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d3dc27c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 80699ef93e0bdc7dbffd03183bbce614deebb1b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 18:07:33 +0000 Subject: [PATCH 26/59] 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 2829a7a..81818ab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 081b9ee..e5aa8db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From c069e91aef75006b25078b5adf33f85ad4c170aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:50:24 +0000 Subject: [PATCH 27/59] Remove files --- index.d.ts | 808 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6990 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 0fe4150..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df28084..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5315b26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;kqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d3dc27c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f22e6167e022b51f0530f5c48592df051d564cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:51:33 +0000 Subject: [PATCH 28/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 42 files changed, 6213 insertions(+), 7175 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fc05d93..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:57:18.392Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 9ecba89..0fe4150 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5e33560 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=e(m,o,p,!0),i=t(i,d(j,!0)),r([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..48190bc --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;2qBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 81818ab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index e5aa8db..35f4143 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assign": "github:stdlib-js/ndarray-base-assign#main", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..15e4b7a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From ed8869fa36f9de68cd7ba55d5cf4858b65ce7661 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 11:25:30 +0000 Subject: [PATCH 29/59] 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 2829a7a..81818ab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index fb2d92c..a1ac7a6 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 6082ef08bfaad88198725b55b9c736ce1b3f7295 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 14:55:36 +0000 Subject: [PATCH 30/59] Remove files --- index.d.ts | 808 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6990 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 0fe4150..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5e33560..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=e(m,o,p,!0),i=t(i,d(j,!0)),r([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 48190bc..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;2qBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 15e4b7a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9559cb524bb2582fc51de48a182d805fe0e531f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 14:56:47 +0000 Subject: [PATCH 31/59] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 41 files changed, 6213 insertions(+), 7174 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 9ecba89..0fe4150 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5e33560 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=e(m,o,p,!0),i=t(i,d(j,!0)),r([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..48190bc --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;2qBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 81818ab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index a1ac7a6..35f4143 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assign": "github:stdlib-js/ndarray-base-assign#main", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..45fdd57 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 1f9504f59a641a817fb1217bcbe70c25b9c691bf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:16:59 +0000 Subject: [PATCH 32/59] 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 2829a7a..81818ab 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 1aa7c7f..9df12e9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From f0ac420ffad8414c206e900009232795e113ebd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:33:37 +0000 Subject: [PATCH 33/59] Remove files --- index.d.ts | 808 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6990 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 0fe4150..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5e33560..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=e(m,o,p,!0),i=t(i,d(j,!0)),r([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 48190bc..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;2qBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 45fdd57..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From da3d735d7a4ad5b7fc5b3fe3b932606bdf37c338 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:35:05 +0000 Subject: [PATCH 34/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 42 files changed, 6213 insertions(+), 7170 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 21213b2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T06:02:30.336Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index caf51f3..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c67e099..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 9ecba89..0fe4150 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5e33560 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=e(m,o,p,!0),i=t(i,d(j,!0)),r([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..48190bc --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;2qBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 81818ab..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 9df12e9..35f4143 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assign": "github:stdlib-js/ndarray-base-assign#main", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..726929b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 57b72871b329ac1cecd21c175434e4a2231c5041 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:34:40 +0000 Subject: [PATCH 35/59] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d6dc39..feb2375 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From b4d0e7bd549dcc57f349033a2dae0af646d9fef6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:14:09 +0000 Subject: [PATCH 36/59] Remove files --- index.d.ts | 808 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6990 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 0fe4150..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5e33560..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=e(m,o,p,!0),i=t(i,d(j,!0)),r([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 48190bc..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;2qBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 726929b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5270529cc1320238e7533a9d58484134ff366533 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:14:55 +0000 Subject: [PATCH 37/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 ------ branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 43 files changed, 6213 insertions(+), 7176 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index df13155..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:32:24.101Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index eb6ea82..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -253,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -313,15 +306,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index fc689d0..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 9ecba89..0fe4150 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..17ff797 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5315b26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;kqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 2829a7a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index feb2375..35f4143 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assign": "github:stdlib-js/ndarray-base-assign#main", - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..650458a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 4013e47c0dd933d772cd133d7971f427724b4e73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:37:16 +0000 Subject: [PATCH 38/59] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dfbbb3e..afe8d61 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.0", "@stdlib/ndarray-base-shape": "^0.2.0", "@stdlib/ndarray-base-slice": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 57dbd3294c3ba6396014c2e1da94dc8ce78d786d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:23:20 +0000 Subject: [PATCH 39/59] Remove files --- index.d.ts | 808 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6990 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 0fe4150..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndzeros = require( `@stdlib/ndarray/zeros` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 17ff797..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5315b26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;kqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 650458a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f6864a57a043459706d01d55f6a42c36132e0dee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:24:29 +0000 Subject: [PATCH 40/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 ------ branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 80 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ----- 42 files changed, 6213 insertions(+), 7184 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 13fadab..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -255,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -318,15 +309,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c10af04..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/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 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 45bcbda..778939e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c331517 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7cc7455 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 2829a7a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index afe8d61..df295a0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.2.0", - "@stdlib/ndarray-base-assign": "^0.1.0", - "@stdlib/ndarray-base-broadcast-array": "^0.2.0", - "@stdlib/ndarray-base-dtype": "^0.2.0", - "@stdlib/ndarray-base-shape": "^0.2.0", - "@stdlib/ndarray-base-slice": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/array-zeros": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/complex-float32": "^0.2.0", - "@stdlib/complex-float64": "^0.2.0", - "@stdlib/complex-imag": "^0.2.0", - "@stdlib/complex-real": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-zeros": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-from-scalar": "^0.2.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.2.0", - "@stdlib/slice-multi": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..71c53be --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 57258ff83989831774b8364dec8054e776775f5a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:51:17 +0000 Subject: [PATCH 41/59] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6ab748..bb61d75 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.0-esm/index.mjs'; ``` #### sliceAssign( x, y, slice, strict ) @@ -149,7 +149,7 @@ import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-s import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import ndzeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From c2f2fe93354cfcde2bdf64b85e387be182e574fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:51:17 +0000 Subject: [PATCH 42/59] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb61d75..c2b1eb9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-slice-assign/tags). For example, + ```javascript import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.0-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-s import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import ndzeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.0-esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From b2b2dedf116d672b272298f173808fbb0246c0a0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:53:21 +0000 Subject: [PATCH 43/59] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2829a7a..0457778 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,7 +98,7 @@ function sliceAssign( x, y, s, strict ) { // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); + throw new TypeError( format( '1jPF0', xdt, ydt ) ); } // Resolve a writable output array view: view = slice( y, s, strict, true ); diff --git a/package.json b/package.json index d58669a..93e425a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-slice": "^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 95529907b5ed5e5360db0f20e1819a336324c686 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:13:00 +0000 Subject: [PATCH 44/59] Remove files --- index.d.ts | 808 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6990 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 778939e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c331517..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function i(i,m,o,p){var j,l,h;if(l=a(i),h=a(m),!s(l,h))throw new TypeError(n("invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].",l,h));return j=r(m,o,p,!0),i=t(i,d(j,!0)),e([i,j]),m}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7cc7455..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yqBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,kHAAmHL,EAAKC,IAYtJ,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 71c53be..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a5e95f5e6755edfa45062ab912acfd85968b4713 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:13:40 +0000 Subject: [PATCH 45/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 -------- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 81 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ------- 42 files changed, 4878 insertions(+), 7179 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 10d7835..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -255,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -318,15 +309,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c10af04..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/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 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 45bcbda..778939e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4a8fbe9 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd9cea4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 0457778..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( '1jPF0', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 93e425a..1a96984 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assign": "^0.1.1", - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-slice": "^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-zero-to": "^0.2.0", - "@stdlib/array-typed": "^0.2.0", - "@stdlib/array-zeros": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-empty": "^0.2.0", - "@stdlib/ndarray-from-scalar": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0b3b643 --- /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 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 74d6af0a8f8e31f0a74ce4fe956354b4fe0cc85e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:31:26 +0000 Subject: [PATCH 46/59] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3b4c09..01fb896 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.1-esm/index.mjs'; ``` #### sliceAssign( x, y, slice, strict ) @@ -149,7 +149,7 @@ import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-s import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import ndzeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.1-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 088e2e0da477529cf2569ee703bb52a1f19e79c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:31:26 +0000 Subject: [PATCH 47/59] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01fb896..1228af4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-slice-assign/tags). For example, + ```javascript import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.1-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-s import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import ndzeros from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-zeros@esm/index.mjs'; import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; -import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.1-esm/index.mjs'; +import sliceAssign from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 6ccd1583df3df9535c333f50e382167b01793966 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:25:59 +0000 Subject: [PATCH 48/59] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2829a7a..0457778 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,7 +98,7 @@ function sliceAssign( x, y, s, strict ) { // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); + throw new TypeError( format( '1jPF0', xdt, ydt ) ); } // Resolve a writable output array view: view = slice( y, s, strict, true ); diff --git a/package.json b/package.json index e0b747f..cec2cc1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-slice": "^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 47e316ccdcd9372555ec28b0de90a3cc31a92ce8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 14:03:30 +0000 Subject: [PATCH 49/59] Remove files --- index.d.ts | 808 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5655 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 778939e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4a8fbe9..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dd9cea4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0b3b643..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f188898895f97c3cf5c1a3f0fde25de8da8d4637 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 14:03:49 +0000 Subject: [PATCH 50/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 -------- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 81 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ------- 43 files changed, 4878 insertions(+), 7184 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index dd9465e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:50:20.767Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 10d7835..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -255,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -318,15 +309,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c10af04..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/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 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 45bcbda..778939e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..923d16d --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd9cea4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 0457778..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( '1jPF0', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index cec2cc1..1a96984 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assign": "^0.1.1", - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-slice": "^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-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/array-zeros": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-from-scalar": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..32df1b7 --- /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 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 3ba1b0be9e99915bcbbe996dbc3991ceb28b21d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 04:34:51 +0000 Subject: [PATCH 51/59] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2829a7a..0457778 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,7 +98,7 @@ function sliceAssign( x, y, s, strict ) { // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); + throw new TypeError( format( '1jPF0', xdt, ydt ) ); } // Resolve a writable output array view: view = slice( y, s, strict, true ); diff --git a/package.json b/package.json index e0b747f..cec2cc1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-slice": "^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 9f539ec32b67df45f321b27147b901204ecf26fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 10:19:52 +0000 Subject: [PATCH 52/59] Remove files --- index.d.ts | 808 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5655 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 778939e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 923d16d..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dd9cea4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 32df1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 115b7000fa59414d6cb5bb4a8694e9f57256c0da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 10:20:15 +0000 Subject: [PATCH 53/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 -------- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 81 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ------- 42 files changed, 4878 insertions(+), 7185 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 10d7835..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -255,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -318,15 +309,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c10af04..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/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 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 45bcbda..778939e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..923d16d --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd9cea4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 0457778..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( '1jPF0', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index cec2cc1..1a96984 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assign": "^0.1.1", - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-slice": "^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-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/array-zeros": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-zeros": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-from-scalar": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..32df1b7 --- /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 9e2b6f3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var real = require( '@stdlib/complex-real' ); -var imag = require( '@stdlib/complex-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 0b0d4cee79543ed2a84a27a7c43fed230a5aa552 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:00:00 +0000 Subject: [PATCH 54/59] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2829a7a..0457778 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,7 +98,7 @@ function sliceAssign( x, y, s, strict ) { // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); + throw new TypeError( format( '1jPF0', xdt, ydt ) ); } // Resolve a writable output array view: view = slice( y, s, strict, true ); diff --git a/package.json b/package.json index 2fc1bb6..40a4aab 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 83c18a8e492eb8be978b21be151ecf781bea3120 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:18:51 +0000 Subject: [PATCH 55/59] Remove files --- index.d.ts | 808 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5655 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 778939e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 923d16d..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dd9cea4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 32df1b7..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d9e7878558766d6cfa1aed4e78ef597558dc5d92 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:19:24 +0000 Subject: [PATCH 56/59] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 ------- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ------ 44 files changed, 4878 insertions(+), 7450 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e677ef8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:53:43.703Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a4e76b5..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 10d7835..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -255,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -318,15 +309,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c10af04..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/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 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 45bcbda..778939e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..fe1e076 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd9cea4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 0457778..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( '1jPF0', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 40a4aab..1a96984 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assign": "^0.1.1", - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/array-zeros": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/complex-float64-imag": "^0.1.1", - "@stdlib/complex-float64-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.3.0", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-from-scalar": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/slice-multi": "^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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4189c3f --- /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 6c95356..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); From 019e2c905fac233ca6bf8258e88c9ea7ab23e13f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:22:27 +0000 Subject: [PATCH 57/59] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2829a7a..0457778 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var assign = require( '@stdlib/ndarray-base-assign' ); var slice = require( '@stdlib/ndarray-base-slice' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,7 +98,7 @@ function sliceAssign( x, y, s, strict ) { // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) ); + throw new TypeError( format( '1jPF0', xdt, ydt ) ); } // Resolve a writable output array view: view = slice( y, s, strict, true ); diff --git a/package.json b/package.json index 2fc1bb6..40a4aab 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From d9abbf1b0179aefa2763d39e2bb90376e897a564 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:51:52 +0000 Subject: [PATCH 58/59] Remove files --- index.d.ts | 808 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5655 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 778939e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,808 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float64ndarray, s: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: float32ndarray, s: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int32ndarray, s: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int16ndarray, s: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: int8ndarray, s: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint32ndarray, s: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint16ndarray, s: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8ndarray, s: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: uint8cndarray, s: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex128ndarray, s: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -*/ -declare function sliceAssign( x: ndarray, y: complex64ndarray, s: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: genericndarray, s: MultiSlice, strict: boolean ): genericndarray; - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* ## Notes -* -* - The input array must be broadcast compatible with the output array view to which elements will be assigned. -* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array). -* -* @param x - input array -* @param y - output array -* @param s - multi-slice object for the output array -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ] -*/ -declare function sliceAssign( x: ndarray, y: typedndarray, s: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = sliceAssign; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index fe1e076..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dd9cea4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4189c3f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 28179066ec269ab534fef9633542f6bd9eef55a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:52:19 +0000 Subject: [PATCH 59/59] 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 | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 1824 ------- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 158 - examples/index.js | 95 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 119 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1470 ------ 44 files changed, 4878 insertions(+), 7453 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) 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 04728d3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T01:14:22.740Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a1698c2..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 675105f..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign) 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 10d7835..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: '28 4 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -255,7 +246,7 @@ var a6 = ndarray2array( y ); ## 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]. @@ -318,15 +309,15 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice-assign/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts +[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm -[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts +[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray-same-kind-casts/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/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 421a435..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1824 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var baseZeros = require( '@stdlib/ndarray-base-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [], 'row-major' ), - baseZeros( 'float32', [], 'row-major' ), - baseZeros( 'int32', [], 'row-major' ), - baseZeros( 'complex128', [], 'row-major' ), - baseZeros( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [], { 'dtype': 'float64' } ), - zeros( [], { 'dtype': 'float32' } ), - zeros( [], { 'dtype': 'int32' } ), - zeros( [], { 'dtype': 'complex128' } ), - zeros( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2 ], 'row-major' ), - baseZeros( 'float32', [ 2 ], 'row-major' ), - baseZeros( 'int32', [ 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2 ], 'row-major' ), - baseZeros( 'generic', [ 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1 ], { 'dtype': 'float64' } ), - empty( [ 1 ], { 'dtype': 'float32' } ), - empty( [ 1 ], { 'dtype': 'int32' } ), - empty( [ 1 ], { 'dtype': 'complex128' } ), - empty( [ 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'int32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,broadcasted', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - values = [ - baseEmpty( 'float64', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'float32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'int32', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'complex128', [ 1, 1, 1, 1, 1 ], 'row-major' ), - baseEmpty( 'generic', [ 1, 1, 1, 1, 1 ], 'row-major' ) - ]; - y = [ - baseZeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseZeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var y; - var s; - var i; - var j; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float64' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'float32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'int32' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ), - empty( [ 1, 1, 1, 1, 1 ], { 'dtype': 'generic' } ) - ]; - y = [ - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c10af04..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-slice-assign/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 338cc47..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceAssign from '../docs/types/index'; -export = sliceAssign; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c29d716..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=p(function(w,u){ -var c=require('@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast/dist'),q=require('@stdlib/ndarray-base-broadcast-array/dist'),y=require('@stdlib/ndarray-base-assign/dist'),l=require('@stdlib/ndarray-base-slice/dist'),i=require('@stdlib/ndarray-base-dtype/dist'),d=require('@stdlib/ndarray-base-shape/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,n,o){var a,t,s;if(t=i(e),s=i(r),!c(t,s))throw new TypeError(f('1jPF0',t,s));return a=l(r,n,o,!0),e=q(e,d(a,!0)),y([e,a]),r}u.exports=g -});var h=v();module.exports=h; -/** @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 5d4070c..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 isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar assign = require( '@stdlib/ndarray-base-assign' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceAssign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @module @stdlib/ndarray-base-slice-assign\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\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,EAAmB,QAAS,2DAA4D,EACxFC,EAAY,QAAS,sCAAuC,EAC5DC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAS,QAAS,uBAAwB,EA8D9C,SAASC,EAAaC,EAAGC,EAAGC,EAAGC,EAAS,CACvC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAMT,EAAUI,CAAE,EAClBM,EAAMV,EAAUK,CAAE,EAGb,CAACT,EAAkBa,EAAKC,CAAI,EAChC,MAAM,IAAI,UAAWR,EAAQ,kHAAmHO,EAAKC,CAAI,CAAE,EAG5J,OAAAF,EAAOT,EAAOM,EAAGC,EAAGC,EAAQ,EAAK,EAGjCH,EAAIP,EAAWO,EAAGH,EAAUO,EAAM,EAAK,CAAE,EAGzCV,EAAQ,CAAEM,EAAGI,CAAK,CAAE,EAGbH,CACR,CAKAV,EAAO,QAAUQ,IC7CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isMostlySafeCast", "broadcast", "assign", "slice", "getDType", "getShape", "format", "sliceAssign", "x", "y", "s", "strict", "view", "xdt", "ydt", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 9004b70..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( x, y, slice, strict ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - Parameters - ---------- - x: ndarray - Input array. The input array must be broadcast compatible with the - output array view and must have a data type which can be safely cast to - the output array data type. Floating-point data types (both real and - complex) are allowed to downcast to a lower precision data type of the - same kind (e.g., element values from a 'float64' input array can be - assigned to corresponding elements in a 'float32' output array). - - y: ndarray - Output array. - - slice: MultiSlice - Multi-slice object specifying the output array view. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var y = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ) - - > var x = {{alias:@stdlib/ndarray/from-scalar}}( 3.0 ) - - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var out = {{alias}}( x, y, s, false ) - - > var bool = ( out === y ) - true - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ [ 0.0, 3.0 ], [ 0.0, 3.0 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 729c090..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 empty = require( '@stdlib/ndarray-base-empty' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import MultiSlice = require( '@stdlib/slice-multi' ); -import sliceAssign = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, false ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( '10', y, s, false ); // $ExpectError - sliceAssign( 10, y, s, false ); // $ExpectError - sliceAssign( false, y, s, false ); // $ExpectError - sliceAssign( true, y, s, false ); // $ExpectError - sliceAssign( null, y, s, false ); // $ExpectError - sliceAssign( [], y, s, false ); // $ExpectError - sliceAssign( {}, y, s, false ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s, false ); // $ExpectError - - sliceAssign( '10', y, s, true ); // $ExpectError - sliceAssign( 10, y, s, true ); // $ExpectError - sliceAssign( false, y, s, true ); // $ExpectError - sliceAssign( true, y, s, true ); // $ExpectError - sliceAssign( null, y, s, true ); // $ExpectError - sliceAssign( [], y, s, true ); // $ExpectError - sliceAssign( {}, y, s, true ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an ndarray... -{ - const x = zeros( [ 2, 2 ] ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, '10', s, false ); // $ExpectError - sliceAssign( x, 10, s, false ); // $ExpectError - sliceAssign( x, false, s, false ); // $ExpectError - sliceAssign( x, true, s, false ); // $ExpectError - sliceAssign( x, null, s, false ); // $ExpectError - sliceAssign( x, [], s, false ); // $ExpectError - sliceAssign( x, {}, s, false ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, false ); // $ExpectError - - sliceAssign( x, '10', s, true ); // $ExpectError - sliceAssign( x, 10, s, true ); // $ExpectError - sliceAssign( x, false, s, true ); // $ExpectError - sliceAssign( x, true, s, true ); // $ExpectError - sliceAssign( x, null, s, true ); // $ExpectError - sliceAssign( x, [], s, true ); // $ExpectError - sliceAssign( x, {}, s, true ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a multi-slice object... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, '5', false ); // $ExpectError - sliceAssign( x, y, 5, false ); // $ExpectError - sliceAssign( x, y, false, false ); // $ExpectError - sliceAssign( x, y, true, false ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, undefined, false ); // $ExpectError - sliceAssign( x, y, [ '5' ], false ); // $ExpectError - sliceAssign( x, y, {}, false ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, false ); // $ExpectError - - sliceAssign( x, y, '5', true ); // $ExpectError - sliceAssign( x, y, 5, true ); // $ExpectError - sliceAssign( x, y, false, true ); // $ExpectError - sliceAssign( x, y, true, true ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, undefined, true ); // $ExpectError - sliceAssign( x, y, [ '5' ], true ); // $ExpectError - sliceAssign( x, y, {}, true ); // $ExpectError - sliceAssign( x, y, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign( x, y, s, '5' ); // $ExpectError - sliceAssign( x, y, s, 5 ); // $ExpectError - sliceAssign( x, y, s, null ); // $ExpectError - sliceAssign( x, y, s, undefined ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, {} ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - sliceAssign(); // $ExpectError - sliceAssign( x ); // $ExpectError - sliceAssign( x, y ); // $ExpectError - sliceAssign( x, y, s ); // $ExpectError - sliceAssign( x, y, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f77b95e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable new-cap */ - -'use strict'; - -var E = require( '@stdlib/slice-multi' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var ndzeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var sliceAssign = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create an output ndarray: -var y = ndzeros( [ 3, 3, 3 ] ); - -// Update each matrix... -var s1 = E( 0, _, _ ); -sliceAssign( scalar2ndarray( 100 ), y, s1, false ); - -var a1 = ndarray2array( slice( y, s1, false ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2, false ); - -var a2 = ndarray2array( slice( y, s2, false ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3, false ); - -var a3 = ndarray2array( slice( y, s3, false ) ); -console.log( a3 ); -// => [ [ 300, 300, 300 ], [ 300, 300, 300 ], [ 300, 300, 300 ] ] - -// Update the second rows in each matrix: -var s4 = E( _, 1, _ ); -sliceAssign( scalar2ndarray( 400 ), y, s4, false ); - -var a4 = ndarray2array( slice( y, s4, false ) ); -console.log( a4 ); -// => [ [ 400, 400, 400 ], [ 400, 400, 400 ], [ 400, 400, 400 ] ] - -// Update the second columns in each matrix: -var s5 = E( _, _, 1 ); -sliceAssign( scalar2ndarray( 500 ), y, s5, false ); - -var a5 = ndarray2array( slice( y, s5, false ) ); -console.log( a5 ); -// => [ [ 500, 500, 500 ], [ 500, 500, 500 ], [ 500, 500, 500 ] ] - -// Return the contents of the entire ndarray: -var a6 = ndarray2array( y ); -console.log( a6 ); -/* => - [ - [ - [ 100, 500, 100 ], - [ 400, 500, 400 ], - [ 100, 500, 100 ] - ], - [ - [ 200, 500, 200 ], - [ 400, 500, 400 ], - [ 200, 500, 200 ] - ], - [ - [ 300, 500, 300 ], - [ 400, 500, 400 ], - [ 300, 500, 300 ] - ] - ] -*/ diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 45bcbda..778939e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray, typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0bf1ffc --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-mostly-safe-data-type-cast@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assign@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,m,o,j){var p,l,h;if(l=d(n),h=d(m),!s(l,h))throw new TypeError(a("1jPF0",l,h));return p=e(m,o,j,!0),n=r(n,i(p,!0)),t([n,p]),m}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dd9cea4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isMostlySafeCast from '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast';\nimport broadcast from '@stdlib/ndarray-base-broadcast-array';\nimport assign from '@stdlib/ndarray-base-assign';\nimport slice from '@stdlib/ndarray-base-slice';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.\n*\n* @param {ndarray} x - input array\n* @param {ndarray} y - output array\n* @param {MultiSlice} s - multi-slice object for the output array\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @throws {Error} input array must be broadcast compatible with an output array view\n* @throws {TypeError} input array cannot be safely cast to the output array data type\n* @returns {ndarray} output array\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n* import ndarray from '@stdlib/ndarray-ctor';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* // Define an input array:\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* // Define an output array:\n* var y = ndzeros( [ 2, 3, 2 ], {\n* 'dtype': x.dtype\n* });\n*\n* // Create a slice:\n* var s0 = null;\n* var s1 = new Slice( null, null, -1 );\n* var s2 = new Slice( null, null, -1 );\n* var s = new MultiSlice( s0, s1, s2 );\n* // returns \n*\n* // Perform assignment:\n* var out = sliceAssign( x, y, s, false );\n* // returns \n*\n* var bool = ( out === y );\n* // returns true\n*\n* arr = ndarray2array( y );\n* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]\n*/\nfunction sliceAssign( x, y, s, strict ) {\n\tvar view;\n\tvar xdt;\n\tvar ydt;\n\n\txdt = getDType( x );\n\tydt = getDType( y );\n\n\t// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point...\n\tif ( !isMostlySafeCast( xdt, ydt ) ) {\n\t\tthrow new TypeError( format( '1jPF0', xdt, ydt ) );\n\t}\n\t// Resolve a writable output array view:\n\tview = slice( y, s, strict, true );\n\n\t// Broadcast the input array:\n\tx = broadcast( x, getShape( view, true ) );\n\n\t// Set elements from `x` in `y`:\n\tassign( [ x, view ] );\n\n\t// Return the original output array:\n\treturn y;\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","strict","view","xdt","ydt","getDType","isMostlySafeCast","TypeError","format","slice","broadcast","getShape","assign"],"mappings":";;yrBA0FA,SAASA,EAAaC,EAAGC,EAAGC,EAAGC,GAC9B,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAME,EAAUP,GAChBM,EAAMC,EAAUN,IAGVO,EAAkBH,EAAKC,GAC5B,MAAM,IAAIG,UAAWC,EAAQ,QAASL,EAAKC,IAY5C,OATAF,EAAOO,EAAOV,EAAGC,EAAGC,GAAQ,GAG5BH,EAAIY,EAAWZ,EAAGa,EAAUT,GAAM,IAGlCU,EAAQ,CAAEd,EAAGI,IAGNH,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c92f8b9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @module @stdlib/ndarray-base-slice-assign -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceAssign = require( '@stdlib/ndarray-base-slice-assign' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ - -// 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 0457778..0000000 --- a/lib/main.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isMostlySafeCast = require( '@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast' ); -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var assign = require( '@stdlib/ndarray-base-assign' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view. -* -* @param {ndarray} x - input array -* @param {ndarray} y - output array -* @param {MultiSlice} s - multi-slice object for the output array -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} input array must be broadcast compatible with an output array view -* @throws {TypeError} input array cannot be safely cast to the output array data type -* @returns {ndarray} output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* // Define an input array: -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* // Define an output array: -* var y = ndzeros( [ 2, 3, 2 ], { -* 'dtype': x.dtype -* }); -* -* // Create a slice: -* var s0 = null; -* var s1 = new Slice( null, null, -1 ); -* var s2 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1, s2 ); -* // returns -* -* // Perform assignment: -* var out = sliceAssign( x, y, s, false ); -* // returns -* -* var bool = ( out === y ); -* // returns true -* -* arr = ndarray2array( y ); -* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ] -*/ -function sliceAssign( x, y, s, strict ) { - var view; - var xdt; - var ydt; - - xdt = getDType( x ); - ydt = getDType( y ); - - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the output data type is floating-point... - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( '1jPF0', xdt, ydt ) ); - } - // Resolve a writable output array view: - view = slice( y, s, strict, true ); - - // Broadcast the input array: - x = broadcast( x, getShape( view, true ) ); - - // Set elements from `x` in `y`: - assign( [ x, view ] ); - - // Return the original output array: - return y; -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index 40a4aab..1a96984 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-assert-is-mostly-safe-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assign": "^0.1.1", - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/array-zeros": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/complex-float64-imag": "^0.1.1", - "@stdlib/complex-float64-real": "^0.1.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-zeros": "^0.3.0", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-from-scalar": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/slice-ctor": "^0.2.2", - "@stdlib/slice-multi": "^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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4189c3f --- /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 6c95356..0000000 --- a/test/test.js +++ /dev/null @@ -1,1470 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline, max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isComplexDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var azeros = require( '@stdlib/array-zeros' ); -var typedarray = require( '@stdlib/array-typed' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var sliceAssign = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceAssign, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=false)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (strict=true)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = zeros( [] ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null, null ), - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds output array bounds', function test( t ) { - var values; - var slices; - var x; - var s; - var i; - - x = zeros( [] ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], slices[ i ] ), RangeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'in non-strict mode, the function does not set element values when a slice exceeds output array bounds', function test( t ) { - var actual; - var values; - var slices; - var z; - var x; - var s; - var v; - var i; - - x = scalar2ndarray( 3, 'uint8', 'row-major' ); - - values = [ - zeros( [ 1 ], { 'dtype': 'float64' } ), - zeros( [ 1, 1 ], { 'dtype': 'float32' } ), - zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), - zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), - zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) - ]; - - s = new Slice( 10, 20, 1 ); - slices = [ - new MultiSlice( 10 ), - new MultiSlice( null, s ), - new MultiSlice( s, null, null ), - new MultiSlice( s, s, null, null ), - new MultiSlice( 0, null, null, null, 10 ) - ]; - for ( i = 0; i < values.length; i++ ) { - v = values[ i ]; - actual = sliceAssign( x, v, slices[ i ], false ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), numel( v.shape ), 'returns expected value' ); - t.strictEqual( actual.dtype, v.dtype, 'returns expected value' ); - - z = actual.iget( 0 ); - if ( v.dtype === 'complex128' ) { - t.strictEqual( real( z ), 0, 'returns expected value' ); - t.strictEqual( imag( z ), 0, 'returns expected value' ); - } else { - t.strictEqual( z, 0, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function throws an error if provided an input array which is not broadcast compatible with an output array view', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 10 ] ), - zeros( [ 10, 10 ] ), - zeros( [ 10, 10, 10 ] ), - zeros( [ 10, 10 ] ) - ]; - - values = [ - zeros( [ 2 ] ), - zeros( [ 2, 2 ] ), - zeros( [ 2, 2, 2 ] ), - zeros( [ 2, 2, 2, 2 ] ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( 0, 0, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), Error, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function throws an error if provided an input array having a data type which cannot be safely cast to the data type of the output array', function test( t ) { - var values; - var slices; - var x; - var i; - - x = [ - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'uint8' } ) - ]; - - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2, 2 ], { 'dtype': 'float32' } ), - zeros( [ 2, 2, 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int8' } ) - ]; - - slices = [ - new MultiSlice( null ), - new MultiSlice( null, null ), - new MultiSlice( null, null, null ), - new MultiSlice( null, null, null, null ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( x[ i ], values[ i ], slices[ i ] ), TypeError, 'throws an error when provided ' + slices[ i ].toString() ); - } - t.end(); - - function badValues( x, y, s ) { - return function badValues() { - sliceAssign( x, y, s, true ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3.14, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new baseCtor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var y; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - y = new ctor( x.dtype, typedarray( zeroTo( 10 ), x.dtype ), [], [ 0 ], 7, x.order ); - s = new MultiSlice(); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var idx; - var x; - var y; - var s; - var i; - - x = [ - scalar2ndarray( 100, 'float64', 'row-major' ), - scalar2ndarray( 50, 'float32', 'row-major' ), - scalar2ndarray( 200, 'int32', 'row-major' ), - scalar2ndarray( 300, 'uint32', 'row-major' ) - ]; - - values = [ - array( typedarray( zeroTo( 4 ), 'float64' ), { - 'shape': [ 2, 2 ], - 'dtype': 'float64' - }), - array( typedarray( zeroTo( 8 ), 'float32' ), { - 'shape': [ 2, 2, 2 ], - 'dtype': 'float32' - }), - array( typedarray( zeroTo( 2 ), 'int32' ), { - 'shape': [ 2 ], - 'dtype': 'int32' - }), - array( typedarray( zeroTo( 16 ), 'uint32' ), { - 'shape': [ 2, 2, 2, 2 ], - 'dtype': 'uint32' - }) - ]; - idx = [ - [ 0, 1 ], - [ 0, 1, 0 ], - [ 0 ], - [ 0, 1, 0, 1 ] - ]; - slices = [ - MultiSlice.apply( null, idx[ 0 ] ), - MultiSlice.apply( null, idx[ 1 ] ), - MultiSlice.apply( null, idx[ 2 ] ), - MultiSlice.apply( null, idx[ 3 ] ) - ]; - expected = [ - 100, - 50, - 200, - 300 - ]; - for ( i = 0; i < values.length; i++ ) { - y = values[ i ]; - s = slices[ i ]; - actual = sliceAssign( x[ i ], y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get.apply( actual, idx[ i ] ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all output array dimensions are reduced, the function supports assigning to a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var buf; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; - var s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - x = scalar2ndarray( 3.14, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1 ), 3.14, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - x = scalar2ndarray( 6.28, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 0, 1 ), 6.28, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( 9.52, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), 9.52, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - y = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - x = scalar2ndarray( -1.0, dt, ord ); - - actual = sliceAssign( x, y, s, true ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.strictEqual( actual.get( 1, 1, 2 ), -1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=1)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 6 ], [ 2 ], 4, 'row-major' ); // [ 4, 6, 8, 10, 12, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 6, 'row-major' ); // [ 6, 10, 14 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 14, 0, 10, 0, 6 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 3 ], [ 4 ], 4, 'row-major' ); // [ 4, 8, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 12, 0, 8, 0, 4, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 6, 'row-major' ); // [ 6, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 6, 0, 0, 12, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 3 ], [ 2 ], 8, 'row-major' ); // [ 8, 10, 12 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 12, 10, 8, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); // [ [ 4, 6, 8 ], [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 4 ], 10, 'row-major' ); // [ [ 10, 14 ], [ 22, 26 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 26, 0, 22 ], - [ 0, 0, 0 ], - [ 14, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 12, 2 ], 4, 'row-major' ); // [ [ 4, 6 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 18, 16, 0 ], - [ 0, 0, 0 ], - [ 6, 4, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 6, 2 ], 10, 'row-major' ); // [ [ 10, 12 ], [ 16, 18 ] ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 16, 18, 0 ], - [ 10, 12, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 30 ), 'float64' ); - - // Second column: - x = new ctor( 'float64', xbuf, [ 4 ], [ 6 ], 7, 'row-major' ); // [ 7, 13, 19, 25 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s = new MultiSlice( null, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 7, 0 ], - [ 0, 13, 0 ], - [ 0, 19, 0 ], - [ 0, 25, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 4 ], 11, 'row-major' ); // [ 11, 15 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 15, 0, 11 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - x = new ctor( 'float64', xbuf, [ 2 ], [ 12 ], 9, 'row-major' ); // [ 9, 21 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 21 ], - [ 0, 0, 0 ], - [ 0, 0, 9 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a row: - x = new ctor( 'float64', xbuf, [ 2 ], [ 2 ], 11, 'row-major' ); // [ 11, 13 ] - - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 5, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 11, 13, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Full slice: - x = new ctor( 'float64', xbuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 10, 'row-major' ); // [ [ [ 10, 12, 14 ], [ 16, 18, 20 ], [ 22, 24, 26 ], [ 28, 30, 32 ] ], [ [ 34, 36, 38 ], [ 40, 42, 44 ], [ 46, 48, 50 ], [ 52, 54, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 4 ], 16, 'row-major' ); // [ [ [ 16, 20 ], [ 28, 32 ] ], [ [ 40, 44 ], [ 52, 56 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 56, 0, 52 ], - [ 0, 0, 0 ], - [ 44, 0, 40 ] - ], - [ - [ 0, 0, 0 ], - [ 32, 0, 28 ], - [ 0, 0, 0 ], - [ 20, 0, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - x = new ctor( 'float64', xbuf, [ 2, 2, 2 ], [ 24, 12, 2 ], 10, 'row-major' ); // [ [ [ 10, 12 ], [ 22, 24 ] ], [ [ 34, 36 ], [ 46, 48 ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 24, 22, 0 ], - [ 0, 0, 0 ], - [ 12, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 48, 46, 0 ], - [ 0, 0, 0 ], - [ 36, 34, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - x = new ctor( 'float64', xbuf, [ 1, 2, 2 ], [ 24, 6, 2 ], 16, 'row-major' ); // [ [ [ 16, 118 ], [ 22, 24 ] ] ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 22, 24, 0 ], - [ 16, 18, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function assigns input array element values to corresponding elements in an output array view (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( zeroTo( 100 ), 'float64' ); - - // Second row and second column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 24 ], 67, 'row-major' ); // [ 67, 91 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s = new MultiSlice( null, 1, 1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 67, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 91, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 3 ], [ 12, 2 ], 53, 'row-major' ); // [ [ 53, 55, 57 ], [ 65, 67, 69 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 69, 67, 65 ], - [ 0, 0, 0 ], - [ 57, 55, 53 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - x = new ctor( 'float64', xbuf, [ 2, 2 ], [ 24, 4 ], 59, 'row-major' ); // [ [ 59, 63 ], [ 83, 87 ] ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 83, 0, 87 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 59, 0, 63 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set part of a column: - x = new ctor( 'float64', xbuf, [ 2 ], [ 6 ], 65, 'row-major' ); // [ 65, 71 ] - - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ -24, -6, -2 ], 99, 'row-major' ); - - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 65 ], - [ 0, 0, 71 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=1)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 10, 10, 10, 10, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 10, 0, 10 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 10, 0, 10, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Skip every three elements, starting from second element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 10, 0, 0, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 6 ], [ 2 ], 4, 'row-major' ); - - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ 0, 0, 10, 10, 10, 0 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=2)', function test( t ) { - var expected; - var actual; - var ybuf; - var s0; - var s1; - var x; - var y; - var s; - - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); - - // Full slice: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other row, starting from second-to-last row: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 30, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 4, 3 ], [ 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports broadcasting (ndims=3)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var s2; - var x; - var y; - var s; - - xbuf = typedarray( [ 10.0 ], 'float64' ); - x = new ctor( 'float64', xbuf, [ 1, 1 ], [ 1, 1 ], 0, 'row-major' ); - - // Full slice: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s = new MultiSlice( null, null, null ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ], - [ - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ], - [ 10, 10, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, -1 ); - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ], - [ - [ 0, 0, 0 ], - [ 10, 0, 10 ], - [ 0, 0, 0 ], - [ 10, 0, 10 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( null, null, 1 ); - s1 = new Slice( 2, null, -2 ); - s2 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 10, 10, 0 ], - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Set a sub-array: - ybuf = azeros( 100, x.dtype ); - y = new ctor( x.dtype, ybuf, [ 2, 4, 3 ], [ 24, 6, 2 ], 4, 'row-major' ); - - s0 = new Slice( 0, 1, 1 ); - s1 = new Slice( 2, 0, -1 ); - s2 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = sliceAssign( x, y, s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - - expected = [ - [ - [ 0, 0, 0 ], - [ 10, 10, 0 ], - [ 10, 10, 0 ], - [ 0, 0, 0 ] - ], - [ - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ], - [ 0, 0, 0 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports safely casting input array elements to the data type of the output array', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float32', 'row-major' ), - scalar2ndarray( 10, 'int8', 'row-major' ), - scalar2ndarray( 10, 'uint16', 'row-major' ), - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex64( 3.0, 5.0 ), 'complex64', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float64' } ), - zeros( [ 2 ], { 'dtype': 'int16' } ), - zeros( [ 2 ], { 'dtype': 'uint32' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ), - zeros( [ 2 ], { 'dtype': 'complex128' } ) - ]; - expected = [ - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10 ], - [ 10, 10, 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -}); - -tape( 'the function supports downcasting floating-point input array elements to an output array data type of the same kind', function test( t ) { - var expected; - var values; - var actual; - var x; - var s; - var v; - var e; - var i; - var j; - - s = new MultiSlice( null ); - - x = [ - scalar2ndarray( 10, 'float64', 'row-major' ), - scalar2ndarray( new Complex128( 3.0, 5.0 ), 'complex128', 'row-major' ) - ]; - values = [ - zeros( [ 2 ], { 'dtype': 'float32' } ), - zeros( [ 2 ], { 'dtype': 'complex64' } ) - ]; - expected = [ - [ 10, 10 ], - [ 3, 5, 3, 5 ] - ]; - for ( i = 0; i < expected.length; i++ ) { - actual = sliceAssign( x[ i ], values[ i ], s, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual, values[ i ], 'returns expected value' ); - - v = actual.data; - e = expected[ i ]; - if ( isComplexDataType( actual.dtype ) ) { - for ( j = 0; j < v.legnth; j++ ) { - t.strictEqual( real( v[ j ] ), e[ j*2 ], 'returns expected value' ); - t.strictEqual( imag( v[ j ] ), e[ (j*2)+1 ], 'returns expected value' ); - } - } else { - for ( j = 0; j < v.length; j++ ) { - t.strictEqual( v[ j ], e[ j ], 'returns expected value' ); - } - } - } - t.end(); -});