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 e461b04..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-23T01:02:34.005Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index f0feeee..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/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 05f9e55..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/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 3aad2f2..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: '27 3 * * 1' - - # 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 + + ```
@@ -354,7 +345,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]. @@ -417,25 +408,25 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-assign/main/LICENSE -[@stdlib/slice/ctor]: https://github.com/stdlib-js/slice-ctor +[@stdlib/slice/ctor]: https://github.com/stdlib-js/slice-ctor/tree/esm -[@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 -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 360cf33..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,133 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' ); -var pkg = require( './../package.json' ).name; -var sliceAssign = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var x; - var v; - var s; - var i; - - x = scalar2ndarray( 3, { - 'dtype': 'int8' - }); - - 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' ) - ]; - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceAssign( x, values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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,separate_arguments', function benchmark( b ) { - var values; - var x; - var v; - var i; - - x = scalar2ndarray( 3, { - 'dtype': 'int8' - }); - - 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' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceAssign( x, values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.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,array', function benchmark( b ) { - var values; - var x; - var v; - var i; - - x = scalar2ndarray( 3, { - 'dtype': 'int8' - }); - - 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' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceAssign( x, values[ i%values.length ], [ null, null ] ); - if ( typeof v !== '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/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5758184..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1864 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== 'object' ) { - b.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 opts; - 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 ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % values.length; - v = sliceAssign( values[ j ], y[ j ], s, opts ); - if ( typeof v !== '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 9979247..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/slice-assign" -%% click B href "https://github.com/stdlib-js/ndarray-slice-assign/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-assign/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-assign/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-assign/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-assign/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-assign -[production-url]: https://github.com/stdlib-js/ndarray-slice-assign/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-assign/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-assign/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-assign/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-assign/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-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 732fde6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var h=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var g=h(function(k,c){"use strict";var m=require("@stdlib/assert-is-ndarray-like"),d=require("@stdlib/assert-is-multi-slice"),w=require("@stdlib/assert-is-array-like-object"),f=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,q=require("@stdlib/ndarray-base-assert-is-read-only"),y=require("@stdlib/assert-has-own-property"),b=require("@stdlib/slice-multi"),S=require("@stdlib/slice-base-args2multislice"),E=require("@stdlib/ndarray-base-slice-assign"),T=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function O(t,r,o){var n,i,u,a,l,v,e;if(u={strict:!0},i=arguments.length,!m(t))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",t));if(!m(r))throw new TypeError(s("invalid argument. Second argument must be an ndarray. Value: `%s`.",r));if(q(r))throw new Error("invalid argument. Cannot write to a read-only array.");if(f(arguments[i-1])){if(i-=1,n=arguments[i],y(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));u.strict=n.strict}if(l=T(r),i===2&&l.length>0)throw new RangeError(s("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",l.join(","),0))}if(d(o)){if(v=o,i>3)throw new Error("invalid invocation. Too many arguments.")}else{if(w(o)){if(a=o,i>3)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=2;e\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 );\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 ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar S;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( !isndarrayLike( y ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', y ) );\n\t}\n\tif ( isReadOnly( y ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot write to a read-only array.' );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( y );\n\t\tif ( nargs === 2 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 3 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 3 ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 2; i < nargs; i++ ) {\n\t\t\t\targs.push( arguments[ i ] );\n\t\t\t}\n\t\t}\n\t\ttry {\n\t\t\tS = args2multislice( args );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\t// Search for the first offending value...\n\t\t\tfor ( i = 0; i < args.length; i++ ) {\n\t\t\t\ttry {\n\t\t\t\t\tnew MultiSlice( args[ i ] ); // eslint-disable-line no-new\n\t\t\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Slice arguments must be either a Slice, integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, y, S, opts.strict );\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-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-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 );\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,EAAgB,QAAS,gCAAiC,EAC1DC,EAAe,QAAS,+BAAgC,EACxDC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,mCAAoC,EACpDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAuE9C,SAASC,EAAaC,EAAGC,EAAGC,EAAI,CAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAE,CAAE,EAExG,GAAKT,EAAYS,CAAE,EAClB,MAAM,IAAI,MAAO,sDAAuD,EAEzE,GAAKX,EAAe,UAAWc,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBX,EAAYU,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWL,EAAQ,+DAAgE,SAAUK,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKV,EAAUI,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYT,EAAQ,uIAAwIS,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKnB,EAAcc,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKf,EAAmBa,CAAE,GAEzB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAK,KAAM,UAAWG,CAAE,CAAE,EAG5B,GAAI,CACHD,EAAIb,EAAiBW,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAIf,EAAYY,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWZ,EAAQ,sGAAuG,OAAQQ,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOb,EAAMI,EAAGC,EAAGO,EAAGH,EAAK,MAAO,CACnC,CAKAnB,EAAO,QAAUa,ICvGjB,IAAIY,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "isReadOnly", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "sliceAssign", "x", "y", "s", "options", "nargs", "opts", "args", "sh", "S", "i", "err", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 0966f14..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,71 +0,0 @@ - -{{alias}}( x, y, ...s[, options] ) - Assigns element values from a broadcasted input ndarray to corresponding - elements in an output ndarray view. - - The function supports three (mutually exclusive) means of providing slice - arguments: - - 1. Providing a single MultiSlice object. - 2. Providing a single array containing slice arguments. - 3. Providing slice arguments as separate arguments. - - An individual slice argument must be either a Slice, an integer, null, or - undefined. - - In all cases, the number of slice dimensions must match the number of output - array dimensions. - - If providing a MultiSlice object or an array of slice arguments, no other - slice arguments should be provided. - - Mixing function invocation styles (e.g., providing multiple MultiSlice - objects or providing an array of slice arguments followed by additional - slice arguments) is not supported. - - 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. The output array must be writable. - - s: ...MultiSlice|Slice|null|undefined|integer|ArrayLike - Slice arguments. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - 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 ) - - > 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 6225c0a..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,234 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - sliceAssign( zeros( sh ), empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - sliceAssign( zeros( sh ), empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - sliceAssign( zeros( sh ), empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - sliceAssign( zeros( sh ), empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - sliceAssign( zeros( sh ), empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - sliceAssign( zeros( sh ), empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - sliceAssign( zeros( sh ), empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - sliceAssign( zeros( sh ), empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - sliceAssign( zeros( sh ), empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - sliceAssign( zeros( sh ), empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - sliceAssign( zeros( sh ), empty( 'uint8c', sh, order ), s, { 'strict': 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 ); // $ExpectError - sliceAssign( 10, y, s ); // $ExpectError - sliceAssign( false, y, s ); // $ExpectError - sliceAssign( true, y, s ); // $ExpectError - sliceAssign( null, y, s ); // $ExpectError - sliceAssign( [], y, s ); // $ExpectError - sliceAssign( {}, y, s ); // $ExpectError - sliceAssign( ( x: number ): number => y, y, s ); // $ExpectError - - sliceAssign( '10', y, s, {} ); // $ExpectError - sliceAssign( 10, y, s, {} ); // $ExpectError - sliceAssign( false, y, s, {} ); // $ExpectError - sliceAssign( true, y, s, {} ); // $ExpectError - sliceAssign( null, y, s, {} ); // $ExpectError - sliceAssign( [], y, s, {} ); // $ExpectError - sliceAssign( {}, y, s, {} ); // $ExpectError - sliceAssign( ( x: number ): number => x, y, s, {} ); // $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 ); // $ExpectError - sliceAssign( x, 10, s ); // $ExpectError - sliceAssign( x, false, s ); // $ExpectError - sliceAssign( x, true, s ); // $ExpectError - sliceAssign( x, null, s ); // $ExpectError - sliceAssign( x, [], s ); // $ExpectError - sliceAssign( x, {}, s ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s ); // $ExpectError - - sliceAssign( x, '10', s, {} ); // $ExpectError - sliceAssign( x, 10, s, {} ); // $ExpectError - sliceAssign( x, false, s, {} ); // $ExpectError - sliceAssign( x, true, s, {} ); // $ExpectError - sliceAssign( x, null, s, {} ); // $ExpectError - sliceAssign( x, [], s, {} ); // $ExpectError - sliceAssign( x, {}, s, {} ); // $ExpectError - sliceAssign( x, ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = zeros( [ 2, 2 ] ); - const y = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceAssign( x, y, null, '5' ); // $ExpectError - sliceAssign( x, y, null, false ); // $ExpectError - sliceAssign( x, y, null, true ); // $ExpectError - sliceAssign( x, y, null, [ '5' ] ); // $ExpectError - sliceAssign( x, y, null, ( x: number ): number => x ); // $ExpectError - - sliceAssign( x, y, null, 1, '5' ); // $ExpectError - sliceAssign( x, y, null, 1, false ); // $ExpectError - sliceAssign( x, y, null, 1, true ); // $ExpectError - sliceAssign( x, y, null, 1, [ '5' ] ); // $ExpectError - sliceAssign( x, y, null, 1, ( x: number ): number => x ); // $ExpectError - - sliceAssign( x, y, null, 1, undefined, '5' ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, false ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, true ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, [ '5' ] ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - sliceAssign( x, y, null, '5', {} ); // $ExpectError - sliceAssign( x, y, null, false, {} ); // $ExpectError - sliceAssign( x, y, null, true, {} ); // $ExpectError - sliceAssign( x, y, null, [ '5' ], {} ); // $ExpectError - sliceAssign( x, y, null, ( x: number ): number => x, {} ); // $ExpectError - - sliceAssign( x, y, null, 1, '5', {} ); // $ExpectError - sliceAssign( x, y, null, 1, false, {} ); // $ExpectError - sliceAssign( x, y, null, 1, true, {} ); // $ExpectError - sliceAssign( x, y, null, 1, [ '5' ], {} ); // $ExpectError - sliceAssign( x, y, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - sliceAssign( x, y, null, 1, undefined, '5', {} ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, false, {} ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, true, {} ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, [ '5' ], {} ); // $ExpectError - sliceAssign( x, y, null, 1, undefined, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - 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, true ); // $ExpectError - sliceAssign( x, y, s, false ); // $ExpectError - sliceAssign( x, y, s, [ '5' ] ); // $ExpectError - sliceAssign( x, y, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option 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, { 'strict': '5' } ); // $ExpectError - sliceAssign( x, y, s, { 'strict': 5 } ); // $ExpectError - sliceAssign( x, y, s, { 'strict': null } ); // $ExpectError - sliceAssign( x, y, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceAssign( x, y, s, { 'strict': {} } ); // $ExpectError - sliceAssign( x, y, s, { 'strict': ( 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, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 388319b..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-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 ); - -var a1 = ndarray2array( slice( y, s1 ) ); -console.log( a1 ); -// => [ [ 100, 100, 100 ], [ 100, 100, 100 ], [ 100, 100, 100 ] ] - -var s2 = E( 1, _, _ ); -sliceAssign( scalar2ndarray( 200 ), y, s2 ); - -var a2 = ndarray2array( slice( y, s2 ) ); -console.log( a2 ); -// => [ [ 200, 200, 200 ], [ 200, 200, 200 ], [ 200, 200, 200 ] ] - -var s3 = E( 2, _, _ ); -sliceAssign( scalar2ndarray( 300 ), y, s3 ); - -var a3 = ndarray2array( slice( y, s3 ) ); -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 ); - -var a4 = ndarray2array( slice( y, s4 ) ); -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 ); - -var a5 = ndarray2array( slice( y, s5 ) ); -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 c0436ce..768d455 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,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 { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aaa158 --- /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/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-assign@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function p(p,a,c){var f,v,g,b,w,x,y;if(g={strict:!0},v=arguments.length,!s(p))throw new TypeError(h("1jT4f",p));if(!s(a))throw new TypeError(h("1jTF1",a));if(n(a))throw new Error(h("1jTEs"));if(e(arguments[v-1])){if(o(f=arguments[v-=1],"strict")){if(!i(f.strict))throw new TypeError(h("1jT2o","strict",f.strict));g.strict=f.strict}if(w=l(a),2===v&&w.length>0)throw new RangeError(h("1jTEt",w.join(","),0))}if(t(c)){if(x=c,v>3)throw new Error(h("1jT0m"))}else{if(r(c)){if(b=c,v>3)throw new Error(h("1jT0m"))}else for(b=[],y=2;y\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 );\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 ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar S;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jT4f', x ) );\n\t}\n\tif ( !isndarrayLike( y ) ) {\n\t\tthrow new TypeError( format( '1jTF1', y ) );\n\t}\n\tif ( isReadOnly( y ) ) {\n\t\tthrow new Error( format('1jTEs') );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1jT2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( y );\n\t\tif ( nargs === 2 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jTEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 3 ) {\n\t\t\tthrow new Error( format('1jT0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 3 ) {\n\t\t\t\tthrow new Error( format('1jT0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 2; i < nargs; i++ ) {\n\t\t\t\targs.push( arguments[ i ] );\n\t\t\t}\n\t\t}\n\t\ttry {\n\t\t\tS = args2multislice( args );\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\t// Search for the first offending value...\n\t\t\tfor ( i = 0; i < args.length; i++ ) {\n\t\t\t\ttry {\n\t\t\t\t\tnew MultiSlice( args[ i ] ); // eslint-disable-line no-new\n\t\t\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\t\t\tthrow new TypeError( format( '1jTEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, y, S, opts.strict );\n}\n\n\n// EXPORTS //\n\nexport default sliceAssign;\n"],"names":["sliceAssign","x","y","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isReadOnly","Error","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;wpCAwGA,SAASA,EAAaC,EAAGC,EAAGC,GAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,QAASf,IAEvC,IAAMa,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAYf,GAChB,MAAM,IAAIgB,MAAOF,EAAO,UAEzB,GAAKG,EAAeP,UAAWP,EAAM,IAAQ,CAG5C,GAAKe,EADLhB,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMgB,EAAWjB,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKc,EAAUpB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIU,WAAYP,EAAQ,QAASR,EAAGgB,KAAM,KAAO,GAExD,CACD,GAAKC,EAActB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAIa,MAAOF,EAAO,cAEnB,CACN,GAAKU,EAAmBvB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIa,MAAOF,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKoB,KAAMf,UAAWF,IAGxB,IACCD,EAAImB,EAAiBrB,EACrB,CAAC,MAAQsB,GAET,IAAMnB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAIoB,EAAYvB,EAAMG,GACtB,CAAC,MAAQmB,GACT,MAAM,IAAId,UAAWC,EAAQ,QAASe,OAAQxB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOsB,EAAM/B,EAAGC,EAAGO,EAAGH,EAAKK,OAC5B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 17122fc..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-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-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 ); -* // 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 c35fd62..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isMultiSlice = require( '@stdlib/assert-is-multi-slice' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var base = require( '@stdlib/ndarray-base-slice-assign' ); -var getShape = require( '@stdlib/ndarray-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 {...*} s - slice arguments -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an ndarray -* @throws {TypeError} must provide valid slice arguments -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of slice dimensions must match the number of output 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 -* @throws {Error} cannot write to a read-only ndarray -* @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 ); -* // 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 ) { - var options; - var nargs; - var opts; - var args; - var sh; - var S; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - if ( !isndarrayLike( y ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', y ) ); - } - if ( isReadOnly( y ) ) { - throw new Error( 'invalid argument. Cannot write to a read-only array.' ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( y ); - if ( nargs === 2 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 3 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 3 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 2; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - try { - S = args2multislice( args ); - } catch ( err ) { // eslint-disable-line no-unused-vars - // Search for the first offending value... - for ( i = 0; i < args.length; i++ ) { - try { - new MultiSlice( args[ i ] ); // eslint-disable-line no-new - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. Slice arguments must be either a Slice, integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); - } - } - } - } - return base( x, y, S, opts.strict ); -} - - -// EXPORTS // - -module.exports = sliceAssign; diff --git a/package.json b/package.json index d4358af..2f0aed0 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,64 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-multi-slice": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-slice-assign": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/string-format": "^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/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-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/slice-ctor": "^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..00384fa --- /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 9135ac6..0000000 --- a/test/test.js +++ /dev/null @@ -1,2751 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, max-lines */ - -'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 provided a first argument which is not an ndarray (multislice)', function test( t ) { - var values; - var y; - var s; - var i; - - y = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - s = new MultiSlice(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( value, y, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var y; - var i; - - y = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( value, y, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var y; - var i; - - y = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( value, y, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray (multislice)', function test( t ) { - var values; - var x; - var s; - var i; - - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - s = new MultiSlice(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray (array)', function test( t ) { - var values; - var x; - var i; - - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var x; - var i; - - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided a read-only output array (multislice)', function test( t ) { - var x; - var y; - - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 2, 2 ], { - 'readonly': true - }); - - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - sliceAssign( x, y, new MultiSlice( null, null ) ); - } -}); - -tape( 'the function throws an error if provided a read-only output array (array)', function test( t ) { - var x; - var y; - - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 2, 2 ], { - 'readonly': true - }); - - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - sliceAssign( x, y, [ null, null ] ); - } -}); - -tape( 'the function throws an error if provided a read-only output array (slice arguments)', function test( t ) { - var x; - var y; - - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 2, 2 ], { - 'readonly': true - }); - - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - sliceAssign( x, y, null, null ); - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (multislice)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1 ] ); - s = new MultiSlice( null ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1 ] ); - s = [ new Slice() ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (slice argument, ndims=1)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1 ] ); - s = new Slice(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (slice argument, ndims=2)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1, 1 ] ); - s = new Slice(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (slice argument, ndims=3)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1, 1, 1 ] ); - s = new Slice(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (multislice)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1 ] ); - s = new MultiSlice( null ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (slice argument, ndims=1)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (slice argument, ndims=2)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (slice argument, ndims=3)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=2)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var y; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = scalar2ndarray( 2.0, 'float64', 'row-major' ); - y = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceAssign( x, y, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (multislice)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - 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 ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - 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, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (array)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ 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 ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (array, options)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ 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, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ 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() { - if ( s.length === 1 ) { - return sliceAssign( x, y, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceAssign( x, y, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceAssign( x, y, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - slices = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ 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() { - if ( s.length === 1 ) { - return sliceAssign( x, y, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceAssign( x, y, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceAssign( x, y, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of output array dimensions (no slice arguments, options)', function test( t ) { - var values; - var x; - var i; - - x = scalar2ndarray( 0, 'float64', 'row-major' ); - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( y ) { - return function badValue() { - sliceAssign( x, y, {} ); - }; - } -}); - -tape( 'by default, 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 ); - }; - } -}); - -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, { - 'strict': 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 ], { - 'strict': 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 ); - }; - } -}); - -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 ); - }; - } -}); - -tape( 'the function supports assigning to a zero-dimensional array view (base, multislice)', 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 ); - 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, array)', 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 = []; - - actual = sliceAssign( x, y, s ); - 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, slice arguments)', function test( t ) { - var actual; - var x; - var y; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - y = scalar2ndarray( 0.0, x.dtype, x.order ); - - actual = sliceAssign( x, y ); - 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 ); - 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 ); - 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 ); - 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 ); - 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 ); - 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 ); - 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 ); - 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, multislice)', 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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=1, array)', 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 = [ null ]; - actual = sliceAssign( x, y, s ); - - 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 Slice( null, null, -2 ) ]; - actual = sliceAssign( x, y, s ); - - 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 Slice( 4, null, -2 ) ]; - actual = sliceAssign( x, y, s ); - - 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 Slice( 1, null, 3 ) ]; - actual = sliceAssign( x, y, s ); - - 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 Slice( 4, 1, -1 ) ]; - actual = sliceAssign( x, y, s ); - - 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=1, slice arguments)', 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 = null; - actual = sliceAssign( x, y, s ); - - 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 Slice( null, null, -2 ); - actual = sliceAssign( x, y, s ); - - 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 Slice( 4, null, -2 ); - actual = sliceAssign( x, y, s ); - - 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 Slice( 1, null, 3 ); - actual = sliceAssign( x, y, s ); - - 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 Slice( 4, 1, -1 ); - actual = sliceAssign( x, y, s ); - - 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, multislice)', 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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, array)', 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 = [ null, null ]; - actual = sliceAssign( x, y, s ); - - 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 = [ s0, s1 ]; - actual = sliceAssign( x, y, s ); - - 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 = [ s0, s1 ]; - actual = sliceAssign( x, y, s ); - - 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 = [ s0, s1 ]; - actual = sliceAssign( x, y, s ); - - 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, slice arguments)', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var s0; - var s1; - var x; - var y; - - 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' ); - - s0 = null; - s1 = null; - actual = sliceAssign( x, y, s0, s1 ); - - 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 ); - actual = sliceAssign( x, y, s0, s1 ); - - 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 ); - actual = sliceAssign( x, y, s0, s1 ); - - 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 ); - actual = sliceAssign( x, y, s0, s1 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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 ); - - 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(); -});